Repository navigation
x11-randr: create new modes with the pixel clock in Hz - #7
Open
UTMapp-bot wants to merge 1 commit into
Open
UTMapp-bot wants to merge 1 commit into
UTMapp-bot wants to merge 1 commit into
Conversation
When no mode of the requested size exists, the agent creates one with set_reduced_cvt_mode(). That function comes from the X server's xf86cvt.c, where a mode's clock is in kHz, and it still computes dotClock in kHz. XRRModeInfo.dotClock is in Hz, so every mode the agent created ran 1000 times too slowly: 60 Hz became 0.06 Hz. For example, xrandr shows "1840x1010-0 0.124MHz ... clock 0.06Hz". A compositor that paces its repaints to the output's refresh rate then updates the screen about once a second. KWin 5.27 on X11 does this on Ubuntu 24.04 with virtio-gpu after a dynamic-resolution resize, while the X server and applications keep running normally. Keep the computation and its rounding to the CVT clock step in kHz, then convert the result to Hz: - Cap the clock at what the protocol's 32-bit field holds, so a huge mode on a 32-bit guest gets a lower refresh rate instead of wrapping around to a meaningless one. - An older agent may already have left such modes in the running X server, and find_mode_by_size() would hand them back. Replace a mode of the requested size whose clock is below 1 MHz, which no real mode uses, instead of using it again. Tested in an Ubuntu 24.04 aarch64 guest (KWin 5.27.11 X11, virgl) on UTM 5.0.9 with dynamic resolution. Each figure is the distinct frames per second the host window showed while a window moved: - Before, the agent created 3840x957-0 and 3840x961-0 at 0.06 Hz: 0.5 fps, with frames held for up to 3.4 s. - After, in the same X server, the agent replaced the stale 3840x961-0 (0.237 MHz) with 237.000 MHz (59.91 Hz). It created 1920x961-0 at 59.91 Hz and 2560x961-0 at 59.94 Hz: 47.2 fps on 3840x961-0. Resolves utmapp/UTM#8197 Assisted-by: Claude:claude-opus-5-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the X11 agent has to create a mode for a new display size, the mode runs at 0.06 Hz instead of 60 Hz. In UTM issue utmapp/UTM#8197 the reporter's guest ended up on
1840x1010-0 0.124MHz ... v: ... clock 0.06Hzafter a dynamic-resolution resize. KWin 5.27 (X11, OpenGL compositing on virgl) then updates the screen about once a second, while X and applications keep running normally. Turning off dynamic resolution, or suspending compositing, avoids it.Cause
set_reduced_cvt_mode()insrc/vdagent/x11-randr.cwas taken from the X server'sxf86cvt.cand still computes the clock in kHz ("kHz for xf86").XRRModeInfo.dotClockis in Hz, so every mode the agent created was 1000 times too slow. Whether the agent's mode or the kernel's mode of the same size ends up current varies with each resize. The same code is in spice-vdagent 0.22.1 (Ubuntu 24.04) and upstream master.Fix
Testing
Ubuntu 24.04 aarch64 guest (KWin 5.27.11 X11, Mesa 25.2.8 virgl,
virtio-gpu-gl-pci) on UTM 5.0.9 with dynamic resolution. Both agents were built from this tree, before and after the change, and run as the session's agent. The figures are the distinct frames per second the host window showed while a window moved in the guest.3840x957-0/3840x961-03840x961-0(the stale 0.237 MHz mode, replaced)1920x961-0,2560x961-0set_reduced_cvt_mode()compiled from each tree, with its 1920x957 mode set through XRandR in the same KWin session: 0.123 MHz / 0.06 Hz gave 0.7 fps with holds up to 1.7 s, and 122.75 MHz / 59.91 Hz gave 40.8 fps. The old function reproduces the reporter's exact timings for 1840x1010 (0.1245 MHz, 1888/1920/2000, 1013/1023/1039).Not covered by this change: the agent rounds the width down to a multiple of 8 and creates modes without sync polarity flags. Both are older behaviour, unrelated to this bug.
Resolves utmapp/UTM#8197
🤖 Generated with Claude Code